**Analysis_Main.do**

********************************************************************************************************************
********************************************************************************************************************

*This code replicates analyses presented in the paper. Our code for the Appendix can be found in the replication file under the name "Analysis_Appendix.do"

*The code below requires that the following program is installed: iemargins

*To install iemargins, run the following code:*
net from "https://github.com/bbdaniels/iemargins/raw/master/"

*Set your working directory so that you can input data, and so that tables and figures are output to an appropriate folder*
cd " "

*Load Data*
use Data.dta, clear

*****************************************************************
*****************************************************************
*Figure 2: Willingness to Trade Pork and Policy in Experiment 1**
*****************************************************************
*****************************************************************

preserve
*Only keep data from Experiment 1
keep if Treatment==1
*Generate unique identifier
gen case_id = _n

*In each period, a subject stated three different voting thresholds:
*One for each non-preferred interest group, and one for their preferred interest group*
*Here, we first create variables corresponding each of a subject's two voting thresholds for non-preferred groups*
gen VT_New_NonPreferred_One=VT_IG1 if Bargaining_PeakPref==2 | Bargaining_PeakPref==3
replace VT_New_NonPreferred_One=VT_IG3 if Bargaining_PeakPref==1

gen VT_New_NonPreferred_Two=VT_IG2 if Bargaining_PeakPref==3 | Bargaining_PeakPref==1
replace VT_New_NonPreferred_Two=VT_IG3 if Bargaining_PeakPref==2

*Only keep required variables*
keep VT_New_NonPreferred_One VT_New_NonPreferred_Two Bargaining_PeakPref Treatment SubjectID case_id Period Ses_num GroupComp InMajority Topic VT_Preferred VT_NonPreferred

*Reshape dataset to long, so that each subject has three voting tresholds in a given period: one for each non-preferred *
*interest group, and one for their preferred interest group*
reshape long VT_New_, i(case_id) j(VTNonPref_Location) string

*Note: this means that there are duplicates of stated voting thresholds for preferred interest groups. Figure 1 appears the same if we only include a single observation of each preferred interest group voting threshold by running the code below: 
*bysort case_id: replace VT_Preferred=. if _n!=1

drop VT_NonPreferred
ren VT_New_ VT_NonPreferred

*Create CDF*
cumul VT_Preferred, gen(cVT_Preferred)
cumul VT_NonPreferred, gen(cVT_NonPreferred)
stack cVT_Preferred VT_Preferred cVT_NonPreferred VT_NonPreferred, into(c VT) wide clear
lab var cVT_Preferred "Preferred Interest Group"
lab var cVT_NonPreferred "Non-Preferred Interest Group"
sort cVT_NonPreferred cVT_Preferred
line cVT_Preferred cVT_NonPreferred VT, ylab(, grid) ytitle("Cumulative Probability") xlab(, grid) xtitle("Voting Threshold ($0-$10)") legend(size(vsmall)) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) 
graph export "Figure 2.pdf", as(pdf) replace

restore

*******************************************
*Statistical tests reported in footnote 18*
*******************************************

preserve
keep if Treatment==1
gen case_id = _n

*As before, generate a separate observation for each stated voter threshold*
gen VT_NonPreferred_One=VT_IG1 if Bargaining_PeakPref==2 | Bargaining_PeakPref==3
replace VT_NonPreferred_One=VT_IG3 if Bargaining_PeakPref==1

gen VT_NonPreferred_Two=VT_IG2 if Bargaining_PeakPref==3 | Bargaining_PeakPref==1
replace VT_NonPreferred_Two=VT_IG3 if Bargaining_PeakPref==2

keep VT_NonPreferred_One VT_NonPreferred_Two Bargaining_PeakPref Treatment SubjectID case_id Period Ses_num GroupComp InMajority Topic VT_Preferred 

reshape long VT_, i(case_id) j(VT_New_) string

*Comparing likelihood of a $0 voter threshold, and mean demanded amount, by whether interest group was preferred or not*
tab VT_, gen(demand)
gen Pref=1 if VT_New_=="Preferred" 
replace Pref=0 if VT_New_!="Preferred" 
*Two-sample two-tailed tests of proportions willing to accept $0.*
prtest demand1, by(Pref)
*Two-sample two-tailed test of mean demanded amounts.*
ttest VT_, by(Pref)
restore

*******************************************
*Statistical test reported in footnote 19*
*******************************************

*Kolmogorov-Smirnov test of equality of distribution functions*
preserve
keep if Treatment==1 
gen case_id = _n
drop VT_IG1 VT_IG2 VT_IG3 

*Compare distributions of voter thresholds for preferred and non-preferred interest groups (taking the average of non-preferred interest group thresholds)*
reshape long VT_, i(case_id) j(VT_Location) string
encode VT_Location, gen(Type)
ksmirnov VT_, by(Type)
restore

****************************************************************************************************
****************************************************************************************************
*************Figure 3: How Majority Status Affects the Likelihood of Policy Compromise**************
****************************************************************************************************
****************************************************************************************************
preserve
*Considering majority/minority, so we limit to experiment 1 groups with a minority/majority composition*
keep if Treatment==1 & GroupComp==2

*To produce graphs with clustered standard errors, we use iemargins command*
*See more here: http://blogs.worldbank.org/impactevaluations/tools-trade-using-iemargins-graph-impacts-standard-error-bars-ie-analytics-update
*Information on installation can also be found at top of this do file.*

*******************************************
*Statistical test reported in footnote 21*
*******************************************
prtest Alloc_to_pref, by(InMajority)

*******************************************
******************Figure 3*****************
*******************************************
*For figure 3, we compare the proporion of subjects proposing their own policy by whether they were:*
*In the majority*
gen Fig2=1 if InMajority==1
*In the minority and predicted to choose their own policy*
replace Fig2=2 if InMajority==0 & PredictedOwn_Indiv==1
*In the minority and predicted to NOT choose their own policy*
replace Fig2=3 if InMajority==0 & PredictedOwn_Indiv==0

*Figure*
iemargins Alloc_to_pref, treatment(Fig2) vce(cluster SubjectID) ///
graph( ytitle("% Proposing Preferred Policy") graphregion(color(white) lc(white) lw(med)) bgcolor(white) ylab(,angle(0) nogrid)  xla(, tlength(0))   xtit(" ",placement(center) justification(center)) xla(1 `" "Predicted to Propose" "{it:Preferred} Policy" " " "{subscript:|}{superscript:______________________________}{subscript:|}" "{bf:Majority Players}" "'2 `" "Predicted to Propose" "{it:Preferred} Policy" "' 2.5 `" " " " " " " "{subscript:|}{superscript:____________________________________________________________}{subscript:|}" "{bf:Minority Players}" "' 3 `" "Predicted to Propose" "{it:Non-Preferred} Policy" "') yla(0 "0" .2 "20" .4 "40" .6 "60" .8 "80" 1 "100") legend(off) ///
yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) ///
plotopts(lc(white) lw(thin)  fi(100)) ciopts(lc(black)))
graph export "Figure 3.pdf", as(pdf) replace
restore

****************************************************************************************************
****************************************************************************************************
******************Figure 4: How Majority Status Affects the Distribution of Pork********************
****************************************************************************************************
****************************************************************************************************

preserve
keep if Treatment==1 & GroupComp==2

*We reshape the dataset so that there are multiple observations per person: self-allocated amount, and amount to partners*
*We further disinguish by majority/minority status and, for majority players, by whether the partner was in the minority*
*or majority (for minority players, we average over allocated amounts to the two majority partners)*

***Majority players***
*Transfer amount to minority partner*
gen Trans_ToMin=allocA if A_InMajority==0 & InMajority==1
replace Trans_ToMin=allocB if B_InMajority==0 & InMajority==1
*Transfer amount to other majority partner*
gen Trans_OtherMaj=allocA if A_InMajority==1 & InMajority==1
replace Trans_OtherMaj=allocB if B_InMajority==1 & InMajority==1

*Self-allocation amounts for majority and minority players*
gen Trans_Me_Maj=allocMe if InMajority==1
gen Trans_Me_Min=allocMe if InMajority==0

***Minority players***

*We take the average allocation to the two majority partners*
gen Trans_MajPartner=((allocA + allocB)/2)  if InMajority==0

*Convert to long so that each player has multiple recorded observations: for allocation to self and to partners
gen case_id = _n
keep Trans_ToMin Trans_OtherMaj Trans_Me_Maj Trans_Me_Min Trans_MajPartner InMajority SubjectID case_id Period Ses_num

reshape long Trans_, i(case_id) j(AllocationOther) string

*Drop missing observations
drop if missing(Trans_)

*Recode for Figure*
encode AllocationOther, gen(Allocation_Other)

recode Allocation_Other (2=1) (4=2) (5=3) (3=4) (1=5)

*Relabel
label define AllocationOther_l 1 "Majority Self-Allocation" 2 "Allocation: Other Majority Partner" 3 "Allocation: Minority Partner" 4 "Minority Self Allocation" 5 "Average Allocation: Majority Partner"
label values Allocation_Other AllocationOther_l	

ren Trans_ TransferAmount

*******************************************
*Statistical test reported in footnote 23*
*******************************************
ttest TransferAmount if Allocation_Other==2 | Allocation_Other==3, by(Allocation_Other)

*******************************************
******************Figure 4*****************
*******************************************
iemargins TransferAmount, treatment(Allocation_Other) vce(cluster SubjectID) ///
graph( ytitle("Distribution of $10 of Pork") graphregion(color(white) lc(white) lw(med)) bgcolor(white) ylab(,angle(0) nogrid) xla(, tlength(0)) xtit(" ",placement(center) justification(center)) xla(1 "To Self" 2 `" "To Majority" "Partner" " " "{subscript:|}{superscript:________________________________________________________}{subscript:|}" "{bf:Majority Players}" "' 3 `" "To Minority" "Partner" "' 4 `" "To Self" "' 4.5 `" " " " " " " "{subscript:|}{superscript:__________________________________}{subscript:|}" "{bf:Minority Players}" "' 5 `" "To Majority" "Partners (avg)" "') yla(0 "$0" 1 "$1" 2 "$2" 3 "$3" 4 "$4" 5 "$5" 6 "$6" 7 "$7")  ///
yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) ///
plotopts(lc(white) lw(thin)  fi(100)) ciopts(lc(black)))
graph export "Figure 4.pdf", as(pdf) replace

*******************************************
*Statistical test reported in footnote 24*
*******************************************
*Recode to compare average amount proposed for majority versus minority players*
recode  Allocation_Other (1=1) (2=1) (5=1) (3=2) (4=2)
ttest TransferAmount, by( Allocation_Other)
restore

**********************************************************************************
**********************************************************************************
*****Figure 5: How the Status Quo Affects the Likelihood of Policy Compromise*****
**********************************************************************************
**********************************************************************************

preserve
keep if Treatment==1 & GroupComp==2

*Recode such that we compare cases where the status quo is one's preferred policy (=0) wih cases where the status quo
*is non-preferred (=1)*
recode StatusQuo (1=0) (2=1) (3=1) (4=1) (5=1)

*******************************************
*Statistical test reported in footnote 25*
*******************************************
prtest Alloc_to_pref, by(StatusQuo)

*******************************************
******************Figure 5*****************
*******************************************
*Remove variable label*
label var Alloc_to_pref

*Generate Figure*
iemargins Alloc_to_pref , treatment(StatusQuo) vce(cluster SubjectID) ///
graph( ytitle("% Proposing Preferred Policy") graphregion(color(white) lc(white) lw(med)) bgcolor(white) ylab(,angle(0) nogrid) xla(, tlength(0)) xtit(" ",placement(center) justification(center)) xla(0 `" "Status Quo {it:Matches}" "Preferred Policy" "' 1 `" "Status Quo {it:Does Not Match}" "Preferred Policy" "')  yla(0 "0" .2 "20" .4 "40" .6 "60" .8 "80") legend(off) ///
yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) ///
plotopts(lc(white) lw(thin)  fi(100)) ciopts(lc(black)))
graph export "Figure 5.pdf", as(pdf) replace

*******************************************
*Statistical test reported in footnote 28*
*******************************************
ttest allocMe if InMajority==1, by(StatusQuo)
restore

**********************************************************************************
**********************************************************************************
*******Figure 6: Comparing Predicted and Observed Minority Policy Proposals*******
**********************************************************************************
**********************************************************************************
preserve
*Limit to minority players in experiment 1 in groups with majority/minority composition*
keep if GroupComp==2 & Treatment==1 & InMajority==0

**********************************
*Row 1: predicted minority policy*
**********************************

*Prediction: Preferred policy*
gen PredictedMinority=1 if (Max_Location_Left==1 & Bargaining_PeakPref==1) | (Max_Location_Middle==1 & Bargaining_PeakPref==2) | (Max_Location_Right==1 & Bargaining_PeakPref==3)
*Prediction: Majority policy*
replace PredictedMinority=2 if (Max_Location_Left==1 & A_Peak==1) | (Max_Location_Middle==1 & A_Peak==2) | (Max_Location_Right==1 & A_Peak==3)

*Percentage of minority proposals predicted to be preferred versus majority preferred policy*
tab PredictedMinority 

*******************************
*Row 2: actual minority policy*
*******************************

gen Policy_location=3 // when actual proposed policy is not one's own nor the majority's preferred policy
replace Policy_location=1 if donateIG==Bargaining_PeakPref // when actual proposed policy is preferred
replace Policy_location=2 if InMajority==0 & donateIG==A_Peak // when actual proposed policy is majority's preferred policy

tab Policy_location // Actual policy location: reported in text
tab Policy_location if PredictedMinority==1 // Actual policy locations when predicted policy is preferred
tab Policy_location if PredictedMinority==2 // Actual policy locations when predicted policy is majority's preferred

*************************************************************************
*Row 3: Proposal acceptance rate by predicted and actual minority policy*
*************************************************************************

tab PredictedMinority Policy_location, sum(Accepted)

*Figure 6 was then created in powerpoint using the above output*

*********************************************************
**********************Footnote 27************************
*********************************************************

gen Extremes=0
replace Extremes=1 if  A_Peak==1 & Bargaining_PeakPref==3
replace Extremes=1 if  A_Peak==3 & Bargaining_PeakPref==1

tab Policy_location if Extremes==1

**********************************************************************
*Test reported in text: minority players no more or less likely 
*to propose own or majority's preferred policy depending on prediction
**********************************************************************
tab Policy_location, gen(pol)
prtest pol1, by(PredictedMinority)
prtest pol2, by(PredictedMinority)

**********************************************************************
*Result reported in text: odds of proposal approval rise from 73% to 89% 
*when minority members propose the majority's preferred policy instead of own*

tab Policy_location, sum(Accepted)

restore

*********************************************************
**********************Footnote 29************************
*********************************************************

preserve
*Limit to majority players in experiment 1 in groups with majority/minority composition*
keep if GroupComp==2 & Treatment==1 & InMajority==1

*Did they choose the minority's preferred policy?*
gen Alloc_to_Min=0
replace Alloc_to_Min=1 if (donateIG==A_Peak & InMajority==1 & A_InMajority==0) | (donateIG==B_Peak & InMajority==1 & B_InMajority==0) 
tab Alloc_to_Min if InMajority==1, sum(Accepted)
restore

**********************************************************************************
**********************************************************************************
***Figure 8: How the Presence of Pork Affects the Prospect of Policy Compromise***
**********************************************************************************
**********************************************************************************

preserve
*Limit to Pork & Policy (Treatment 1) and Policy Only (Treatment 3) experiments*
*Limit to groups with a majority(minority composition)*
keep if (Treatment==1 | Treatment==3) & GroupComp==2
recode Treatment (1=0) (3=1)

*********************************************************
**********************Footnote 31************************
*********************************************************
prtest Alloc_to_pref if InMajority==0, by(Treatment)

**********************************************************
****Reported in text: differences for majority players****
**********************************************************
prtest Alloc_to_pref if InMajority==1, by(Treatment)

label define Treatment_l3 0 "Pork & Policy" 1 "Policy Only" 
label values Treatment Treatment_l3

*******************************************
******************Figure 8*****************
*******************************************
gen Fig6=1 if InMajority==1 & Treatment==0
replace Fig6=2 if InMajority==0 & Treatment==0
replace Fig6=3 if InMajority==1 & Treatment==1
replace Fig6=4 if InMajority==0 & Treatment==1

label define Fig6_l 1 "Majority" 2 "Minority" 3 "Majority" 4 "Minority"
label values Fig6 Fig6_l	

*title("Policy Choice by Majority Minority Status (Treatments 1 and 3)", justification(left) color(black) span pos(11))
iemargins Alloc_to_pref , treatment(Fig6) vce(cluster SubjectID) ///
graph( ytitle("% Proposing Preferred Policy", size(small)) graphregion(color(white)  lc(white) lw(med)) bgcolor(white) ylab(,angle(0) nogrid) xla(, tlength(0)) xtit(" ",placement(center) justification(center)) xla(1 `" "Predicted Policy:" "{bf:Always} Preferred" "(Ideological {it:Majority})" "' 1.5 `" " " " "  " " " " " "  "{subscript:|}{superscript:______________________________________________}{subscript:|}" "{bf:Pork & Policy}" "{bf:(Experiment 1)}" "' 2 `" "Predicted Policy:" "{bf:Varies} with Relative" "Preference Intensity" "(Ideological {it:Minority})" "' 3 `" "Predicted Policy:" "{bf:Always} Preferred" "(Ideological {it:Majority})" "' 3.5 `" " " " " "  " " " " " "{subscript:|}{superscript:______________________________________________}{subscript:|}" "{bf:Policy Only}" "{bf:(Experiment 2)}" "' 4 `" "Predicted Policy:" "{bf:Always} Preferred" "(Ideological {it:Minority}," "Ban on Trades for Pork)" "', labsize(small)) yla(0 "0" .2 "20" .4 "40" .6 "60" .8 "80" 1 "100", labsize(small)) ///
yscale(noline) xscale(noline) legend(region(lc(none) fc(none))) ///
plotopts(lc(white) lw(thin)  fi(100)) ciopts(lc(black)))
graph export "Figure 8.pdf", as(pdf) replace
restore

**********************************************************************************
**********************************************************************************
**********Figure 9: How the Presence of Policy Affects Demands for Pork***********
**********************************************************************************
**********************************************************************************

preserve
*Limit to Pork & Policy (Treatment 1) and Pork Only (Treatment 2) experiments*
*We pool across group compositions, in line with Figure 9; however, as with 
*Figure 2, results are robust to limiting to limiting to majority/minority compositions*
keep if Treatment==1 | Treatment==2

*********************************************************
**********************Footnote 33************************
*********************************************************
gen Vt3=VT_Preferred if  Treatment==2
replace Vt3=VT_NonPreferred if Treatment==1

ttest VT_Preferred, by(Treatment)
ttest Vt3, by(Treatment)

**Reported in the text: differences for majority and minority players**
ttest VT_Preferred if InMajority==0 & GroupComp==2, by(Treatment)
ttest VT_Preferred if InMajority==1 & GroupComp==2, by(Treatment)

*******************************************
******************Figure 9*****************
*******************************************

gen VT_T1=VT_Preferred if Treatment==1
gen VT_T2=VT_Preferred if Treatment==2

cumul VT_T1, gen(cVT_T1)
cumul VT_T2, gen(cVT_T2)

stack cVT_T1 VT_T1 cVT_T2 VT_T2, into(c VT) wide clear
drop if missing(VT)

******************************************************
*****Statistical test reported in Figure 9 notes******
******************************************************
gen Type=0 if VT_T1!=.
replace Type=1 if VT_T2!=.
ksmirnov VT, by(Type)

*******************************************
******************Figure*******************
*******************************************
lab var cVT_T1 "Pork & Policy"
lab var cVT_T2 "Pork Only"

sort cVT_T1 cVT_T2
line cVT_T1 cVT_T2 VT, ylab(, grid) ytitle("Cumulative Probability") xlab(, grid) xtitle("Voting Threshold ($0-$10)") legend(size(vsmall)) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) 
graph export "Figure 9.pdf", as(pdf) replace
restore

**********************************************************************************
**********************************************************************************
****************Additional Results Reported in Main Text**************************
**********************************************************************************
**********************************************************************************
preserve
keep if Treatment<4 & GroupComp==2
*Acceptance rates across treatments*
prtest Accepted if Treatment!=1, by(Treatment)
prtest Accepted if Treatment!=2, by(Treatment)
prtest Accepted if Treatment!=3, by(Treatment)
restore

*Acceptance rates across Pork and Policy and Policy Only treatments by Majority/Minority Status (text and footnote 35)*
preserve
keep if (Treatment==1 | Treatment==3) & GroupComp==2
prtest Accepted if InMajority==0, by(Treatment)
prtest Accepted if InMajority==1, by(Treatment)
restore

*The role of information (text and footnote 37)*
tab Treatment if (GroupComp==2 | Treatment==4) & Treatment!=5 & Treatment!=6, sum(Accepted)
tab Treatment if (GroupComp==2 | Treatment==4) & Treatment!=5 & Treatment!=6 & InMajority==0, sum(Accepted)
tab Treatment if (GroupComp==2 | Treatment==4) & Treatment!=5 & Treatment!=6 & InMajority==1, sum(Accepted)

*Impact of using naturally-occuring political preferences (text and footnote 39)*
prtest Accepted if (Treatment==1 | Treatment==5) & GroupComp==2, by(Treatment)
